package gui;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import logic.objects.Node;
import logic.objects.Problem;
import logic.service.PheromonService;

public class ProtocolTable extends JTable {
	private String[] columns = { "Algorithmus", "Kosten der besten Lösung" };
	private ArrayList<String[]> list;
	private Problem problem;

	public ProtocolTable(Problem problem) {
		this.problem = problem;
		initialize();
	}
	public void initialize(){
		list = new ArrayList<String[]>();
		add("Nearest-Neigbor-Heuristic",PheromonService.getNearestNeighborShortedTourValue(problem));
		applyModel();
	}

	public void add(String x, Double y) {
		DecimalFormat format = new java.text.DecimalFormat("#.00");
		String yAlsString = format.format(y);
		String[] array = { x, yAlsString };
		list.add(array);
		applyModel();
	}

	public void removeAll() {
		ArrayList<String[]> remove = new ArrayList<String[]>();
	}

	public String[][] getData() {
		String[][] array = new String[list.size()][2];
		for (int i = 0; i < list.size(); i++) {
			array[i][0] = list.get(i)[0];
			array[i][1] = list.get(i)[1];

		}
		return array;
	}

	public String[] getColumns() {
		return columns;
	}

	public void applyModel() {
		this.setModel(new DefaultTableModel(getData(), getColumns()));
	}
}
